#include <iostream>
#include <unistd.h>
#include <cstdio>
#include <ctime>
using namespace std;

class Clock {
public:
	//构造函数
	Clock (time_t t) {
		tm * local = localtime (&t);
		m_hour = local->tm_hour;
		m_min = local->tm_min;
		m_sec = local->tm_sec;
	}
	void run (void) {
		while (1) {
			printf ("\r %02d:%02d:%02d", m_hour, m_min, m_sec);
			//刷新输出缓冲区
			fflush(stdout);
			if (++m_sec == 60) {
				m_sec = 0;
				if (++m_min == 60) {
					m_min = 0;
					if (++m_hour == 24) {
						m_hour = 0;
					}
				}
			}
			sleep (1);
		}
	}
private:
	int m_hour;
	int m_min;
	int m_sec;
};

int main (void)
{
#if 0
	//在栈区实例化对象
	Clock clock (time(NULL));
	clock.run ();
#endif
	//在堆区创建对象
	Clock *pc  = new Clock (time(NULL));
	pc->run ();
	delete pc;
	pc = NULL;
	return 0;
}
